import axios from 'axios';
import {getFormData,jsonToUrlParameter} from "../../lib/utils";


//响应拦截器
axios.interceptors.response.use(res=>{
    return Promise.resolve(res.data);
})

//请求拦截器
axios.interceptors.request.use(conf=>{
    // conf.header[`${Config.tokenKey}`] = getToken();
    return conf;
})

export function get(url,params){
    console.log("params::",params)
    return axios.get(`${url}?${jsonToUrlParameter(params)}`);
}

// export function post(url,params){
//     return axios.post(url,getFormData(params));
// }

export function post(url,params){
    return axios.post(url,params);
}

export  function postFormDate(url,params){
    return axios.post(url,getFormData(params),{
        headers:{
            'Content-Type':'application/x-www-form-urlencoded'
            // 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
        }
    })
}

export function uploadFile(url,params){
    return axios.post(url,getFormData(params),{
        'Content-Type':'multipart/form-data'
    })
}